﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VipCo.Entities;
using VipCo.Data;

public partial class Controls_GioiThieuControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HienthiGioithieu();
        }
    }

    public void HienthiGioithieu()
    {
        // Tim tin tuc thuoc chuyen muc Gioi thieu va onlycard
        int totalRows = 0;
        TList<NhomTinTuc> entNhomtintuc =
            DataRepository.NhomTinTucProvider.GetPaged("TenNhom like N'" + Common.NhomTinTuc_Gioithieu + "'",
                                                       "Id DESC", 0, 1, out totalRows);

        // Neu ton tai du lieu thi kiem nhom SubTinTuc
        if (entNhomtintuc.Any())
        {
            TList<SubTinTuc> tlistSubtt = DataRepository.SubTinTucProvider.GetByIdNhomTinTuc(entNhomtintuc[0].Id);

            if (tlistSubtt.Any())
            {
                TList<TinTuc> tlistTintuc = DataRepository.TinTucProvider.GetByIdSubTin(tlistSubtt[0].Id);

                if (tlistTintuc.Any())
                {
                    imgGt.ImageUrl = Common.sPathUpTinTuc + tlistTintuc[0].AnhDaiDien;
                    litTomtat.Text = tlistTintuc[0].TomTat;
                }
            }
        }
    }
}